#include "timmingpattern.h"

timmingPattern::timmingPattern()
{

}

void timmingPattern::findTimming(point upperLeft, point upperRight, point lowerLeft, point origin, int pixelProportion, QImage *img)
{
    int dimension = abs(upperRight.getColumn()-upperLeft.getColumn());
    int rowTimming = upperLeft.getRow()+3*pixelProportion;

    pixel p;

    for (int col = origin.getColumn(); col < dimension+origin.getColumn(); col += pixelProportion)
    {
        if (!p.isPattern(rowTimming, col, img))
            p.paintPixel(rowTimming, col, pixelProportion, qRgb(232,229,63), img);
    }

    dimension = abs(lowerLeft.getRow()-upperLeft.getRow());
    int colTimming = upperLeft.getColumn()+3*pixelProportion;
    for (int row = origin.getRow(); row < dimension+origin.getRow(); row += pixelProportion)
    {
        if (!p.isPattern(row, colTimming, img))
            p.paintPixel(row, colTimming, pixelProportion, qRgb(232,229,63), img);
    }

    p.paintPixel(lowerLeft.getRow()-4*pixelProportion, lowerLeft.getColumn()+5*pixelProportion, pixelProportion, qRgb(232,229,63), img);

    converter c;
    log->addLog("\nLINHA DO TIMMING = " + c.intToString(rowTimming));
    log->addLog("\nCOLUNA DO TIMMING = " + c.intToString(colTimming));
}

void timmingPattern::setCanvas(canvas *log)
{
    this->log = log;
}
